package per.sunmes.lesrb.actor;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.scenes.scene2d.Actor;

import per.sunmes.lesrb.apis.ShaderValueUpdate;

public class ShaderActor extends ShadowActor {

	public ShaderActor(Actor target) {
		super(target);
	}

	ShaderProgram shader;
	ShaderProgram oldTmp;
	ShaderValueUpdate shaderUpdater;

	public void setShaderUpdater(ShaderValueUpdate shaderUpdater) {
		this.shaderUpdater = shaderUpdater;
	}

	public ShaderValueUpdate getShaderUpdater() {
		return shaderUpdater;
	}

	public void setShader(ShaderProgram shader) {
		this.shader = shader;
	}

	public ShaderProgram getShader() {
		return shader;
	}

	@Override
	public void draw(Batch batch, float parentAlpha) {
		if (shader != null) {
			oldTmp = batch.getShader();
			batch.setShader(shader);
			if (shaderUpdater != null) {
				shaderUpdater.shaderUpdate(shader);
			}
			super.draw(batch, parentAlpha);
			batch.setShader(oldTmp);
		} else {
			super.draw(batch, parentAlpha);
		}
	}
}
